﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace Trust.Casas.Model.Entities
{
    [Table("AppSetting")]
    public class AppSetting : AuditableEntity
    {
        [StringLength(100)]
        [Key]
        public string Key { get; set; }

        [StringLength(1000)]
        public string Value { get; set; }

        [StringLength(1000)]
        public string Description { get; set; }
        
        public virtual object TypedValue
        {
            get { return Value; }
        }

        public virtual void SetValue(string value)
        {
            if (string.IsNullOrWhiteSpace(value))
                Value = null;
            else
            {
                Value = value;
            }
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}",Key,Value);
        }
    }
}